package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.business.dao.inter.ElderLifeStyleDao;
import com.yunfeisoft.business.model.ElderLifeStyle;
import com.yunfeisoft.business.service.inter.ElderLifeStyleService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.sql.separation.DataSourceChange;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * ClassName: ElderLifeStyleServiceImpl
 * Description: 老人生活方式从表service实现
 * Author: Jackie liu
 * Date: 2020-04-04
 */
@Service("elderLifeStyleService")
public class ElderLifeStyleServiceImpl extends BaseServiceImpl<ElderLifeStyle, String, ElderLifeStyleDao> implements ElderLifeStyleService {

    @Override
    @DataSourceChange(slave = true)
    public Page<ElderLifeStyle> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public ElderLifeStyle getByHealthId(String elderHealthId) {
        return getDao().getByHealthId(elderHealthId);
    }

    @Override
    public void deleteByHealthId(String elderHealthId) {
        getDao().deleteByHealthId(elderHealthId);
    }

    @Transactional
    public void saveElderLifeStyle(ElderLifeStyle record) {
        // 先删除之前的记录
        getDao().deleteByHealthId(record.getElderHealthId());
        // 新增记录
        getDao().insert(record);
    }
}